Skip to content

ReactiveUserControl class

Attributes: [WinRTRuntimeClassName] [WinRTExposedType]

Defined in

Namespace: ReactiveUI.Maui Assembly: ReactiveUI.Maui.dll Full name: ReactiveUI.Maui.ReactiveUserControl<T> Modifiers: public

Summary

View source

A UserControl that is reactive.

Applies to

net10.0-windows10.0.19041, net9.0-windows10.0.19041

Class hierarchy
classDiagram
class ReactiveUserControl~T~
class UserControl
UserControl <|-- ReactiveUserControl~T~
class IViewFor~TViewModel~ {
    <>
}
IViewFor~TViewModel~ <|.. ReactiveUserControl~T~
class IViewFor {
    <>
}
IViewFor <|.. ReactiveUserControl~T~
class IActivatableView {
    <>
}
IActivatableView <|.. ReactiveUserControl~T~

Inherits from: UserControl

Implements: IViewFor, IViewFor, IActivatableView

Remarks

This class is a UserControl that is also reactive. That is, it implements IViewFor. You can extend this class to get an implementation of IViewFor rather than writing one yourself.

Note that the XAML for your control must specify the same base class, including the generic argument you provide for your view model. To do this, use the TypeArguments attribute as follows:

<![CDATA[
 <rxui:ReactiveUserControl
 x:Class="Foo.Bar.Views.YourView"
 x:TypeArguments="vms:YourViewModel"
 xmlns:rxui="http://reactiveui.net"
 xmlns:vms="clr-namespace:Foo.Bar.ViewModels"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 mc:Ignorable="d">
 <!-- view XAML here -->
 </rxui:ReactiveUserControl>
 ]]>

Note that UWP and WinUI projects do not support the TypeArguments attribute. The XAML designer window in WPF projects also does not support generic types. To use ReactiveUserControl in XAML documents you need to create a base class where you derive from ReactiveUserControl with the type argument filled in.

<![CDATA[
 internal class YourViewBase : ReactiveUserControl<YourViewModel> { /* No code needed here */ }
 
 public partial class YourView : YourViewBase
 {
 /* Your code */
 }
 ]]>

Then you can use this base class as root in your XAML document.

<![CDATA[
 <views:YourViewBase
 x:Class="Foo.Bar.Views.YourView"
 xmlns:rxui="http://reactiveui.net"
 xmlns:vms="clr-namespace:Foo.Bar.ViewModels"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 mc:Ignorable="d">
 <!-- view XAML here -->
 </views:YourViewBase>
 ]]>

Constructors

NameSummary
.ctor

Properties

NameSummary
BindingRootGets the binding root view model.
ViewModelGets or sets the strongly typed view model. Override this property to integrate with the platform's binding system.

Fields

NameSummary
static ViewModelPropertyThe view model dependency property.
Inherited members